﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Dal.infDal;
using Dal.Iterfease;
using System.Data.SqlClient;
using Model;
using Dapper;

namespace xiaomiApi.Controllers
{
    /// <summary>
    /// 购物车PAI
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class CartController : ControllerBase
    {
        private readonly ICartDal _userDal;

        public CartController(ICartDal userDal)
        {
            _userDal = userDal;
        }

        /// <summary>
        /// 添加购物车
        /// </summary>
        /// <param name="cart"></param>
        /// <returns></returns>
        [HttpPost, Route("AddCart")]
        public IActionResult AddCart(shoppingCart cart)
        {
            return Ok(_userDal.AddCart(cart));
        }

        /// <summary>
        /// 购物车显示
        /// </summary>:
        /// <param name="Uid"></param>
        /// <returns></returns>
        [HttpGet, Route("showCart")]
        public IActionResult showCart(int Uid)
        {
            var couetsumb = 0;
            var a = _userDal.showCart(Uid,out couetsumb);

           
            return Ok(new { a, couetsumb });
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Scid"></param>
        /// <returns></returns>
        [HttpPost, Route("delCart")]
        public IActionResult delCart(int Scid)
        {
            return Ok(_userDal.delCart(Scid));
        }

        /// <summary>
        /// 数量同步
        /// </summary>
        /// <param name="Scid"></param>
        /// <param name="Ssum"></param>
        /// <returns></returns>
        [HttpPost, Route("UpShoppingCarNum")]
        public IActionResult UpShoppingCarNum(int Scid, int Ssum)
        {
            return Ok(_userDal.UpShoppingCarNum(Scid, Ssum));
        }
    }
}
